<template>
	<view>
		<view class="card">
			<view class="tit">请用户出示券码</view>
			<view class="flex-cs">
				<input type="text" v-model="code_number" placeholder="请输入券码"/>
				<image src="../../static/scan.png" mode="" @tap="scopebtn"></image>
			</view>
			<view class="bottombtn" @tap="save">确认核销券码</view>
		</view>
		<view v-if="show==true" class="btny">
			<mumu-get-qrcode @success='qrcodeSucess' @error="qrcodeError" ></mumu-get-qrcode>
		</view>
		
	</view>
</template>
<script>
	const app = getApp();
	var util = require('../../utils/util.js');
	import mumuGetQrcode from '@/uni_modules/mumu-getQrcode/components/mumu-getQrcode/mumu-getQrcode.vue'
	// 嫌路径长的话可以单独复制出来
	export default {
        components: {
            mumuGetQrcode
        },
		data() {
			return {
				imgoss: app.globalData.imgoss,
				statusBarHeight: getApp().globalData.statusBarHeight,
				statusBarHeight1: getApp().globalData.statusBarHeight1,
				code_number:'',
				show:false
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			this.code_number = options.id
		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady() {

		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow() {
		},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide() {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh() {
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom() {
		},
		methods: {
			qrcodeSucess(data) {
				this.show = false
				this.orderChancelRefund(data)
			},
		  qrcodeError(err) {
			//console.log(err)
			uni.showModal({
			  title: '摄像头授权失败',
			  content: '摄像头授权失败，请检测当前浏览器是否有摄像头权限。',
			  success: () => {
				this.show = false
			  }
			})
		  },
			scopebtn(){
				var that = this;
				this.show = true

			},
			save(){
				if(this.code_number==''){
					app.globalData.show('请输入券码~')
					return true
				}
				this.orderChancelRefund()
			},
			orderChancelRefund(code_number){
				var that = this;
				app.globalData.api.request('Shop/codeNumberSubmit', {
					code_number: code_number?code_number:that.code_number,
				}, 'POST', 'form').then((res) => {
					if (res.code == 0) {
						app.globalData.d('核销成功~')
					} else {
						app.globalData.show(res.msg)
					}
				});
			},
				
			jump(url) {
				//console.log(url)
				uni.navigateTo({
					url: url
				})
			},
		}
	};
</script>
<style lang="scss">
	.btny{
		width: 100%;
		height: 100vh;
		position: fixed;
		top: 0px;
		left: 0px;
	}
	.card{
		background: #fff;
		border-radius: 10rpx;
		padding: 50rpx 30rpx;
		.flex-cs{
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 60rpx;
			border-bottom:  1rpx solid rgba(240,240,240,1);
			padding-bottom: 25rpx;
		}
		.tit{
			color: #101010;
			font-size: 24rpx;
		}
		image{
			width: 37rpx;
			height: 37rpx;
		}
		input{
			width: 100%;
			font-size: 24rpx;
		}
	}
	.bottombtn {
		background: #8665AF;
		border-radius: 10rpx;
		color: #fff;
		margin: 200rpx 60rpx 0;
		text-align: center;
		padding: 20rpx 0;
		font-size: 24rpx;
	}

	page {
		background: #f6f6f6;
		padding: 20rpx 30rpx;
	}
</style>